package pers.bbw.crr.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import pers.bbw.crr.dto.ClubSearchDto;
import pers.bbw.crr.entity.Activity;
import pers.bbw.crr.entity.Club;
import pers.bbw.crr.service.ClubService;
import pers.bbw.crr.util.AjaxResult;

import javax.annotation.Resource;

/**
 * 社团信息控制器
 *
 * @author bbw
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/club")
@Api(tags = "社团信息控制器")
public class ClubController {

    @Resource
    private ClubService clubService;

    /**
     * 查询社团列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public AjaxResult list(@ApiParam(value = "社团信息searchDto") ClubSearchDto dto) {
        PageInfo<Club> page = clubService.selectClubList(dto);
        return AjaxResult.success().put("list", page.getList()).put("total", page.getTotal());
    }

    /**
     * 获取社团详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情", notes = "根据id查询")
    public AjaxResult getInfo(@ApiParam(value = "社团id") @PathVariable("id") int id) {
        return AjaxResult.success(clubService.selectClubById(id));
    }

    /**
     * 新增社团
     */
    @PostMapping
    @ApiOperation(value = "新增")
    public AjaxResult save(@ApiParam(value = "社团信息对象") @RequestBody Club club) {
        if (clubService.save(club) > 0) {
            return AjaxResult.success("创建成功");
        } else {
            return AjaxResult.error("创建失败");
        }

    }

    /**
     * 修改社团信息
     */
    @PutMapping
    @ApiOperation(value = "修改社团信息")
    public AjaxResult edit(@ApiParam(value = "社团信息") @RequestBody Club club) {
        clubService.updateClub(club);
        return AjaxResult.success();
    }

    /**
     * 删除社团
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "批量删除")
    public AjaxResult remove(@ApiParam(value = "社团id数组") @PathVariable int[] ids) {
        if (clubService.deleteClubByIds(ids) > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }

}
